package com.taotao.service.com.taotao.service.Impl;

import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.pojo.TreeNode;
import com.taotao.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mafuhua on 2017/9/24.
 */
@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Autowired
    private TbItemCatMapper tbItemCatMapper;
    @Override
    public List<TreeNode> getItemCatList(long parentId) {
        TbItemCatExample tbItemCatExample = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = tbItemCatExample.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<TbItemCat> tbItemCats = tbItemCatMapper.selectByExample(tbItemCatExample);
        ArrayList<TreeNode> treeNodes = new ArrayList<>();
        for (TbItemCat tbItemCat : tbItemCats) {
            com.taotao.pojo.TreeNode treeNode = new com.taotao.pojo.TreeNode(
                    tbItemCat.getId(),
                    tbItemCat.getName(),
                    tbItemCat.getIsParent()?"closed":"open");
            treeNodes.add(treeNode);

        }
        return treeNodes;
    }
}
